var app = getApp()
Page({
  data: {
    title: '话题列表',
    postsList: [],
    hidden: false,
    page: 1,
    tab: 'all'
  },
  onLoad: function(){
      this.fetchData()
  },
  onTapTag: function (e) {
    var self = this;
    var tab = e.currentTarget.id;
    console.log(e.currentTarget)
    self.setData({
      tab: tab
    });
    if (tab !== 'all') {
      this.fetchData({tab: tab});
    } else {
      this.fetchData();
    }
  },
  fetchData:function(data){
      var _this = this;
      _this.setData({
          hidden: false
      });
      wx.request({
        url: 'https://cnodejs.org/api/v1/topics?page='+_this.data.page+'&tab='+_this.data.tab,
        header: {
            'content-type': 'application/json'
        },
        success: function(res) {
            _this.setData({
                postsList : res.data.data
            });
            setTimeout(function () {
                _this.setData({
                    hidden: true
                });
            }, 300);
            
        }
    })
  },
  tapDetail: function (e) {
    var id = e.currentTarget.id,
        url = '../detail/detail?id=' + id;
    wx.navigateTo({
      url: url
    })
  },
  
});